package com.amc.service.impl;

import java.math.BigInteger;
import java.security.MessageDigest;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.amc.entity.Customer;


@Aspect
@Component
public class EncodeMd5 {


	@Around("execution (public * login(..))")
	public Customer encodeLogin(ProceedingJoinPoint pjp) throws Throwable {
		MessageDigest md = MessageDigest.getInstance("MD5");
		Object[] obj = pjp.getArgs();
		String password=obj[0].toString();
		md.update(obj[1].toString().getBytes());
		String upassword = new BigInteger(1, md.digest()).toString(16);
		obj[1] = upassword;
		Customer userSelect = (Customer) pjp.proceed(obj);
		System.out.println(userSelect + "加密后Customer");
		return userSelect;
		}
	

	@Around("execution (public * register(..))")
	public boolean encodeRegister(ProceedingJoinPoint pjp) throws Throwable {
		MessageDigest md = MessageDigest.getInstance("MD5");
		Object[] obj = pjp.getArgs();
		md.update(obj[1].toString().getBytes());
		String upassword = new BigInteger(1, md.digest()).toString(16);
		obj[1] = upassword;
		boolean result= (boolean) pjp.proceed(obj);
		return result;


	}
}
